package com.yk.business;

import com.yk.client.Loader;
import com.yk.clienthandler.MessageSendHandler;
import com.yk.pojo.ReqMessage;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.UUID;

/**
 * Created by dingkl on 2017/7/28.
 */
public class ProxyHandler implements InvocationHandler{

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("process");
        long indexstartTime = System.currentTimeMillis();
        ReqMessage request = new ReqMessage();
        request.setMessageId(UUID.randomUUID().toString());
        request.setClassName(method.getDeclaringClass().getName());
        request.setMethodName(method.getName());
        request.setParams(method.getParameterTypes());
        request.setObjects(args);
        MessageSendHandler messageSendHandler = Loader.loader().getMessageSendHandler();
        CallBackMsg callBackMsg = messageSendHandler.sendMsg(request);
        Object result = callBackMsg.getResult();
        long indexEndTime = System.currentTimeMillis();
        System.out.println("time--------"+(indexEndTime-indexstartTime));
        return result;
    }

}
